/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GuiBuscarTipoVeiculo.java
 *
 * Created on 27/11/2011, 13:37:45
 */
package view.gui;

import controller.ControllerCliente;
import controller.ControllerTipoVeiculo;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import model.dominio.TipoVeiculo;

/**
 *
 * @author Braulio
 */
public class GuiBuscarTipoVeiculo  extends JInternalFramePermissao {

    private List<TipoVeiculo> lista;

    /** Creates new form GuiBuscarTipoVeiculo */
    public GuiBuscarTipoVeiculo() {
        initComponents();
        
        carregaTabela();
    }

    private void carregaTabela() {
        lista = ControllerTipoVeiculo.buscaListaTipos();
        DefaultTableModel model = (DefaultTableModel) tabelaTipos.getModel();
        model.setRowCount(0);

        String[] s = new String[4];
        for (TipoVeiculo t : lista) {
            s[0] = t.getTipo();
            s[1] = String.valueOf(t.getPrecoBase());
            s[2] = String.valueOf(t.getPrecoKm());
            s[3] = String.valueOf(t.getTaxaUnica());
            model.addRow(s);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaTipos = new javax.swing.JTable();

        setClosable(true);
        setTitle("Tipos de Veículo");
        getContentPane().setLayout(null);

        tabelaTipos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tipo", "Preço Base", "Preço por Km", "Taxa Única"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaTipos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaTiposMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabelaTipos);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(0, 0, 610, 210);

        setBounds(0, 0, 628, 242);
    }// </editor-fold>//GEN-END:initComponents

    private void tabelaTiposMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaTiposMouseClicked
        if (evt.getClickCount() > 1) {
            int linha = tabelaTipos.getSelectedRow();
            GuiPrincipal.addJanela(new GuiDadosTipoVeiculo(lista.get(linha)));
            this.dispose();
        }

    }//GEN-LAST:event_tabelaTiposMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tabelaTipos;
    // End of variables declaration//GEN-END:variables

    @Override
    public int getPermissao() {
        return 17;
    }
}
